package cn.itcast.service.impl;

import cn.itcast.dao.ChangeDao;
import cn.itcast.dao.ChangeListDao;
import cn.itcast.dao.ReqDao;
import cn.itcast.dao.impl.ChangeDaoImpl;
import cn.itcast.dao.impl.ChangeListDaoImpl;
import cn.itcast.dao.impl.ReqDaoImpl;
import cn.itcast.domain.ChangeList;
import cn.itcast.service.ChangeListService;
import org.springframework.dao.DataAccessException;

import java.util.List;

public class ChangeListServiceImpl implements ChangeListService {
    ChangeListDao dao=new ChangeListDaoImpl();
    ReqDao dao1=new ReqDaoImpl();
    ChangeDao dao2=new ChangeDaoImpl();
    @Override
    public List<ChangeList> findAll() {
        return dao.findAll();
    }

    @Override
    public ChangeList findChangeListById(String id) {
        return dao.findChangeListById(Integer.parseInt(id));
    }

    @Override
    public void updateChangeListStateId(ChangeList changelist) {
        int id = changelist.getId();
        int state_id = changelist.getState_id();
        dao.updateChangeListStateId(changelist);
        dao1.updateReqStateId(id,state_id);
        dao2.updateChangeStateId(id,state_id);
    }

    @Override
    public List<ChangeList> findAllByStateId() {
        return dao.findAllByStateId();
    }

    @Override
    public ChangeList findChangeListByIda(String id) {
        return dao.findChangeListByIda(Integer.parseInt(id));
    }

    @Override
    public void updateChangeListChangeState(ChangeList changelist) {
        int id = changelist.getId();
        int change_state = changelist.getChange_state();
        dao.updateChangeListChangeState(changelist);
        dao1.updateReqChangeState(id,change_state);
        dao2.updateChangeChangeState(id,change_state);

    }

    @Override
    public List<ChangeList> findAllByChangeState() {
        return dao.findAllByChangeState();
    }

    @Override
    public ChangeList findChangeListByIdb(String id) {
        return dao.findChangeListByIda(Integer.parseInt(id));
    }

    @Override
    public void updateChangeListCheckState(ChangeList changelist) {
        int id = changelist.getId();
        int check_state = changelist.getCheck_state();
        dao.updateChangeListCheckState(changelist);
        dao1.updateReqCheckState(id,check_state);
        dao2.updateChangeCheckState(id,check_state);
    }
}
